package com.etoak.stock;

import com.etoak.stock.mapper.StockBusinessMapper;
import com.etoak.stock.service.StockTimerTaskService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import org.checkerframework.checker.units.qual.A;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.*;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.web.client.RestTemplate;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @Author by 孙有泽
 * @Date 2024/10/911:33
 * @Description 测试访问别的接口
 */
@SpringBootTest
public class test {
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private StockTimerTaskService stockTimerTaskService;

    @Autowired
    private StockBusinessMapper stockBusinessMapper;

    @Test
    public void test01(){
        String url="http://localhost:6633/account/getByUserNameAndAddress?userName=itheima&address=shanghai";
        ResponseEntity<String> result = restTemplate.getForEntity(url, String.class);
        HttpHeaders headers = result.getHeaders();
        System.out.println(headers);
        HttpStatus statusCode = result.getStatusCode();
        System.out.println(statusCode);
        String body = result.getBody();
        System.out.println(body);
    }
    @Test
    public void test02(){
        String url="http://localhost:6666/account/getHeader";
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("username","zhangsan");
        HttpEntity<Map> objectHttpEntity = new HttpEntity<>(httpHeaders);
        ResponseEntity<String> exchange = restTemplate.exchange(url, HttpMethod.GET, objectHttpEntity, String.class);
        String body = exchange.getBody();
        System.out.println(body);
    }
    @Test
    public void test03(){
        String url="http://localhost:6666/account/addAccount";
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("Content-type","application/x-www-form-urlencoded");
        LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
        map.add("id","10");
        map.add("userName","itheima");
        map.add("address","shanghai");
        HttpEntity<LinkedMultiValueMap<String, Object>> linkedMultiValueMapHttpEntity = new HttpEntity<>(map, httpHeaders);
        ResponseEntity<String> exchange = restTemplate.exchange(url, HttpMethod.POST, linkedMultiValueMapHttpEntity, String.class);

    }
    @Test
    public void test04() throws InterruptedException {
        //stockTimerTaskService.getInnerMarketInfo();
        stockTimerTaskService.getStockRtIndex();
        Thread.sleep(5000);
        //stockTimerTaskService.getStockBlockInfo();
    }
    @Test
    public void test05(){
        PageHelper.startPage(1,10);
        List<String> stockIds = stockBusinessMapper.getStockIds();
        PageInfo<String> stringPageInfo = new PageInfo<>(stockIds);
        stringPageInfo.getPageNum();//当前页码
        stringPageInfo.getPageSize();//每页显示条数
        stringPageInfo.getPages();//总页数
        stringPageInfo.getTotal();//总条数
        stringPageInfo.getList();//当前页数据
        stringPageInfo.getSize();//当前页条数
    }
    @Test
    public void test06(){
        ArrayList<Integer> integers = new ArrayList<>();
        Collections.addAll(integers, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
        List<Integer> collect = integers.stream().filter(x -> x > 5).collect(Collectors.toList());
        System.out.println(collect);
    }
}
